package managedBeans;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
import com.orwa.Employee;
import com.orwa.JDBCConnector;

@ManagedBean(name="empView")
@RequestScoped
public class EmpView {

	private String srchVal;
	private List<Employee> empList;
	
	public String getSrchVal() {
		return srchVal;
	}
	public void setSrchVal(String srchVal) {
		this.srchVal = srchVal;
	}
		
	public List<Employee> getEmpList() {
		return empList;
	}
	
	public String getEmpData(){
		/*System.out.println("inside getEmpData");
		Logger logger = Logger.getLogger("logger");
		logger.severe("inside getEmpData!!!!!!!!!!!!!!!!!!!!!!!!!!!!");*/
		
		JDBCConnector connector = new JDBCConnector();
		Connection HRConn = connector.getHRConn();
		PreparedStatement ps;
		Employee emp = new Employee();
		empList = new ArrayList<Employee>();
		try {
			ps = HRConn.prepareStatement("select  employee_id, first_name, last_name, email, hire_date, salary, manager_id, department_id "+
										 "from    employees "+
										 "where   employee_id = ?");
			ps.setString(1, getSrchVal());
			ResultSet rs = ps.executeQuery();
			rs.next();
			emp.setEmpID(rs.getString("employee_id"));
			emp.setFirstName(rs.getString("first_name"));
			emp.setLastName(rs.getString("last_name"));
			emp.setEmail(rs.getString("email"));
			emp.setHiredate(rs.getString("hire_date"));
			emp.setMgrID(rs.getString("manager_id"));
			emp.setDeptID(rs.getString("department_id"));
			emp.setSalary(rs.getDouble("salary"));
			empList.add(emp);
			
			return "sucess";
			
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return null;
		}
	}

}
